#include "BillRecord.h"

/*
==================
BillRecord::BillRecord
==================
*/
BillRecord::BillRecord() {
	ifstream file("BILLREC.dta");
	
	// If the file is open
	if (file.is_open()) {
		string line;
		vector<string> tmpRecords;
		
		// As long as no error flags is set
		while (file.good()) {
			getline(file, line);

			// Add to the back of the list
			tmpRecords.push_back(line);
		}
		
		numRecords = (unsigned)tmpRecords.size();
		records = new string[numRecords];
		
		// Going through all in tmpRecords and adding them to records
		for (unsigned i = 0; i < numRecords; i++) {
			records[i] = tmpRecords[i];
		}
	} else {
		Warning("Failed to open file: BILLREC.dta");
	}
}

/*
==================
BillRecord::~BillRecord
==================
*/
BillRecord::~BillRecord() {
	if (records) {
		delete[] records;
	}
}

/*
==================
BillRecord::getCount
==================
*/
int BillRecord::getCount() {
	return numRecords;
}

/*
==================
BillRecord::getRecord

When iterating over the records of the BillRecord-object, the 
"getCount" method must be used in conjunction with "getRecord".
==================
*/
string BillRecord::getRecord(unsigned idx) {
	if (idx >= numRecords) {
		Warning("Bad index parameter sent to BillRecrod::getRecord!", idx);
		return "";
	}
	
	return records[idx];
}